<template>
  <van-tabbar id="navbar" route>
    <van-button class="publish_btn" type="primary" @click="gotoNext()" round>+ 上报</van-button>
    <van-tabbar-item replace :to="'/nav/home?openid=' + $route.query.openid">
      <template #icon="props">
        <div class="navwrapper" v-if="isActiveFunction('/nav/home')">
          <img class="navicon" src="../../assets/icon/h-a.png" alt="">
          <span class="navspan" style="color: #3276EB">工作台</span>
        </div>
        <div class="navwrapper" v-else>
          <img class="navicon" src="../../assets/icon/h.png" alt="">
          <span class="navspan">工作台</span>
        </div>
      </template>
    </van-tabbar-item>
    <van-tabbar-item replace :to="'/nav/personal?openid=' + $route.query.openid">
      <template #icon="props">
        <div class="navwrapper" v-if="isActiveFunction('/nav/personal')">
          <img class="navicon" src="../../assets/icon/p-a.png" alt="">
          <span class="navspan" style="color: #3276EB" >我的</span>
        </div>
        <div class="navwrapper" v-else>
          <img class="navicon" src="../../assets/icon/p.png" alt="">
          <span class="navspan">我的</span>
        </div>
      </template>
    </van-tabbar-item>
  </van-tabbar>
</template>

<script>
import { Tabbar,  TabbarItem, Toast} from 'vant'
import {getuserinfoPromise} from "@/api/myapi";
    export default {
        components: {
            [Tabbar.name]: Tabbar,
            [TabbarItem.name]: TabbarItem,
        },
        data() {
            return {
              active: 'home',
              primaryColar: '#1989fa'
            }
        },
      methods: {
        isActiveFunction(path) {
          return this.$route.path.indexOf(path) !== -1?true:false
        },
        async gotoNext() {
          if(!this.$route.query.openid || this.$route.query.openid == 'undefined') return Toast('微信用户未授权')
          const {data} = await getuserinfoPromise(this.$route.query.openid)
          if(data && data.id) {
            this.$router.push('/apply?openid=' + this.$route.query.openid)
          } else {
            Toast('用户未注册')
          }
        }
      }
    }
</script>

<style lang="less" scoped>
  .van-tabbar {
    height: 60px;
    z-index: 0;
  }
  .van-tabbar-item {
    position: relative;
    background: #ffffff;
  }
  .navwrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .navicon {
    width: 20px;
    height: 20px;
  }
  .navicona {
    width: 32px;
    height: 32px;
  }
  .navspan {
    font-size: 12px;
    color: #929292;
    padding-top: 5px;
  }

  .publish_btn {
    position: absolute;
    top: -50px;
    right: 10px;
    height: 36px;
    background: #2064E2;
    box-shadow: -1px 3px 6px rgba(32, 100, 226, 0.43);
    border-color: #2064E2;
  }
</style>
